package com.cccyy.financial_calculations;

public class FundNetValueCalculator {

    /**
     * 计算基金净值
     *
     * @param totalAssets      基金资产总额
     * @param totalLiabilities 基金负债总额
     * @param totalShares      基金总份额
     * @return 净值
     * @throws IllegalArgumentException 如果总份额为零
     */
    public double calculateNetValue(double totalAssets, double totalLiabilities, double totalShares) {
        if (totalShares == 0) {
            throw new IllegalArgumentException("基金总份额不能为零");
        }
        double result = (totalAssets - totalLiabilities) / totalShares;
        System.out.println("基金净值为: " + result);

        return result;
    }

    public static void main(String[] args) {
        FundNetValueCalculator calculator = new FundNetValueCalculator();
        double totalAssets = 1000000.0; // 假设基金资产总额为100万元
        double totalLiabilities = 200000.0; // 假设基金负债总额为20万元
        double totalShares = 50000.0; // 假设基金总份额为5万股

        try {
            double netValue = calculator.calculateNetValue(totalAssets, totalLiabilities, totalShares);
            System.out.println("基金净值为: " + netValue);
        } catch (IllegalArgumentException e) {
            System.err.println(e.getMessage());
        }
    }
}